﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using PowerCreator.LMS.Common.Script;

public partial class Theme_Index_PaperResearchList : System.Web.UI.Page
{

    PowerCreator.LMS.ViewQuery.ViewQuery opViewQuery = new PowerCreator.LMS.ViewQuery.ViewQuery();
    private PowerCreator.LMS.Web.DL.User.LoginEntity login = new PowerCreator.LMS.Web.DL.User.LoginEntity();
    private string url = "UserLogin.aspx";

    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Expires = -1;
        CheckUser();
        this.Title = "调查问卷";
        ViewState["ClassID"] = string.Empty;
        if (!IsPostBack)
        {           
            if (Request.QueryString["ClassID"] != null)
            {
                string classID = Request.QueryString["ClassID"].ToString();
                ViewState["ClassID"] = classID;;
            }
            BinderPage();
        }
    }

    private void CheckUser()
    {
        if (Session[PowerCreator.LMS.Web.Config.WebConfig.SESSION_USER_USERINFO] == null)
        {
            Script.RedirectURL(url);
        }

        login = (PowerCreator.LMS.Web.DL.User.LoginEntity)Session[PowerCreator.LMS.Web.Config.WebConfig.SESSION_USER_USERINFO];
        if (login == null)
        {
            Script.RedirectURL(url);
        }

    }

    private void BinderPage()
    {
        string search = "select *  from PaperResearch  where PaperResearch_StartTime<=getdate() and getdate()<=PaperResearch_EndTime and PaperResearch_ShowState=1 and isnull(PaperRearch_FKClassID,'')='' ";
        if (!string.IsNullOrEmpty(ViewState["ClassID"].ToString()))
        {
            search = "select *  from PaperResearch  where PaperResearch_StartTime<=getdate() and getdate()<=PaperResearch_EndTime and PaperResearch_ShowState=1 and (PaperRearch_FKClassID like '%{0}%' or PaperRearch_FKClassID is null)";
            search = string.Format(search, "," + ViewState["ClassID"].ToString().Trim()+",");
        }
        
        string orderby = " PaperResearch_ID desc";
        DataTable dt = new DataTable();
        int num = opViewQuery.Count(search);
        dt = opViewQuery.Query(search,orderby,num,1);

        rpt_PaperReseach.DataSource = dt;
        rpt_PaperReseach.DataBind();
    }

    protected void rpt_PaperReseach_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName.ToString() == "lstudy")
        {
            Label lbl_ID = (Label)e.Item.FindControl("lbl_ID");  //课程表ID
            login = (PowerCreator.LMS.Web.DL.User.LoginEntity)Session[PowerCreator.LMS.Web.Config.WebConfig.SESSION_USER_USERINFO];
            string url = "OpenPaperResearch.aspx?PaperID=" + lbl_ID.Text + "&ProjectClassID=0&UserID="+login.UserID.ToString();
            PowerCreator.LMS.Common.Script.Script.NewOpenURL(url); 
            //Response.Redirect(url);
        }
        else if (e.CommandName.ToString() == "lsee")
        {
            Label lbl_ID = (Label)e.Item.FindControl("lbl_ID");  //课程表ID
            string url = "../../sysadmin/PaperResearchManager/PaperResearchStatistical.aspx?p=" + lbl_ID.Text;
            PowerCreator.LMS.Common.Script.Script.NewOpenURL(url);
        }
    }


    protected void rpt_PaperReseach_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
        {
            LinkButton lnkbtn_see = (LinkButton)e.Item.FindControl("lnkbtn_see");
            Label lbl_SeeState = (Label)e.Item.FindControl("lbl_SeeState");  //是否允许前台查看结果

            if (lbl_SeeState.Text == "1")
                lnkbtn_see.Enabled = true;
            else
                lnkbtn_see.Enabled = false;
        }
    }

 


}
